<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue">
			<block slot="content">
				<view class="action sub-title">
					<text class="text-xl text-bold text-white">人脸识别</text>
					<text class="text-ABC text-white">login</text>
				</view>
			</block>
		</cu-custom>
		
		<view class="cu-bar bg-white  margin-top-xs">
			<view class="action">
				<text class="cuIcon-title text-cyan"></text>请对准摄像头拍照
			</view>
		</view>
		<view class="bg-white padding ">
			<!-- 拍照功能。。。 -->
			<view class="grid col-4 grid-square flex-sub justify-center">
				<view class="solids" @tap="ChooseImage('imgList')">
					<text class='cuIcon-cameraaddfill'></text>
				</view>
			</view>
		</view>
		<view class="cu-form-group margin-top-xs">
			<textarea :value="imageInfo"  />
		</view>		
	</view>
</template>

<script>
	import { urlTobase64 } from "@/common/utils/common.js"
	import { faceRecognition } from '@/common/api/recognition.js'
	import { getUserInfo } from '@/common/api/user.js'
	export default {
		props: {
			
		},
		data() {
			return {
				imageInfo: ''
			}
		},
		methods: {
			ChooseImage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], // camera 从相机选择， album 从相册选择 
					success: (res) => {
						// this.imageInfo = JSON.stringify(res);
						// console.log('imageInfo', (res))
						let imageSrc = res.tempFilePaths[0]						
						urlTobase64(imageSrc, false).then(data => {
							let base64 = data;
							let opts = {
								"groupId": 71,
								"image": base64,
								"limit": 3,
								"threshold": 10
							}
							
							uni.showLoading({
								title: "识别中"
							})
							
							// 人脸识别
							faceRecognition(opts)
								.then(({data}) => {
									console.log('--------------- 识别成功 --------------\n', data)
									 this.imageInfo = JSON.stringify(data);
									 if (data.resp_code === 0) {
										 let photos = data.datas.photos
										  uni.showToast({
											title:"识别成功"
										 })
									 }
									
								})
								.catch(err => {
									console.log('--------------- 识别失败 --------------\n', err)
		
									uni.showToast({
										title:"识别失败，请重试",
										icon: "none",
										duration:2000
									})
									this.imageInfo = JSON.stringify(err);
								})
								.then(() => {
									uni.hideLoading();
								})
						})
					}
				});
			},			
		}
	}
</script>

<style>

</style>
